package com.hmis.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmis.domain.Item;
import com.hmis.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@Controller
public class ItemDAO implements InitializingBean {

    public static ItemService itemService;
    public static ItemDAO itemDAO;
    @Autowired
    private ItemService item;

    public Item findByName(String itemName) {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("item_name", itemName);
        List<Item> list = itemService.list(queryWrapper);
        Item item = list.get(0);
        return item;
    }

    public Item findById(long itemId) {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("item_id", itemId);
        List<Item> list = itemService.list(queryWrapper);
        Item item = list.get(0);
        return item;
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        itemService = item;
        itemDAO = this;
    }
}
